﻿package client;
import client.SaleComWorker_1_GUI;
import client.SaleComWorker_2_GUI;
import client.SaleComWorker_3_GUI;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;

import server.CompanyInterface;
import server.PersonInterface;

import java.awt.Dialog.ModalityType;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.awt.Font;

public class SaleComPost_GUI extends JDialog {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 *//*public static void main(String[] args){
		 EventQueue.invokeLater(new Runnable(){
			 	 
			public void run() {
				try {
					SaleComPost_GUI frame = new SaleComPost_GUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
});
}
	/**
	 * Create the frame.
	 */
	public SaleComPost_GUI() {
		setTitle("\u804C\u4F4D");
		setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("\u8BF7\u9009\u62E9\u804C\u4F4D\uFF1A");
		label.setFont(new Font("宋体", Font.PLAIN, 15));
		label.setBounds(44, 22, 117, 31);
		contentPane.add(label);
		
		
		
		final Person per=new Person();
		
		
		try
		{
			Configuration config=new Configuration();
			String rmiAddress=config.getRmiAddress();
			final PersonInterface PI=(PersonInterface) Naming.lookup(rmiAddress+"Person");
			final CompanyInterface CI=(CompanyInterface) Naming.lookup(rmiAddress+"Company");
		
			if(PI.getJob(per.getPID()).equals("业务员"))
			{
		JButton button = new JButton("\u4E1A\u52A1\u5458");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SaleComWorker_1_GUI dialog;
				try {
					dispose();
					dialog = new SaleComWorker_1_GUI();
					dialog.setLocationRelativeTo(null);
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
				} catch (MalformedURLException e1) {
					e1.printStackTrace();
				} catch (RemoteException e1) {
					e1.printStackTrace();
				} catch (NotBoundException e1) {
					e1.printStackTrace();
				}
				
			}
		});
		button.setBounds(145, 63, 120, 23);
		contentPane.add(button);
			}
			else if(PI.getJob(per.getPID()).equals("销售总监"))
			{
		JButton button_1 = new JButton("\u9500\u552E\u603B\u76D1");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				SaleComWorker_2_GUI dialog = new SaleComWorker_2_GUI();
				dialog.setLocationRelativeTo(null);
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
		button_1.setBounds(145, 107, 120, 23);
		contentPane.add(button_1);
			}
			else if(PI.getJob(per.getPID()).equals("总裁")){
		JButton button_2 = new JButton("\u603B\u88C1");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				SaleComWorker_3_GUI dialog = new SaleComWorker_3_GUI();
				dialog.setLocationRelativeTo(null);
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
		button_2.setBounds(145, 152, 120, 23);
		contentPane.add(button_2);
			}
	
		JButton button_3 = new JButton("\u8F9E\u804C");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					int pid = per.getPID();
					CI.setStaffNum(PI.getComID(pid), CI.getStaffID(pid));
					PI.apply(pid, "无");
					PI.setComID(pid, 0);
					dispose();
				} catch (RemoteException e) {
					e.printStackTrace();
				}
			}
		});
		button_3.setBounds(282, 199, 120, 23);
		contentPane.add(button_3);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

}
